Skip to content
This repository was archived by the owner on Mar 11, 2025. It is now read-only.

[confidential-transfer] Add confidential transfer ciphertext arithmetic crate #7026

Merged
merged 3 commits into from
Jul 19, 2024

Conversation

samkim-crypto
Copy link
Contributor

@samkim-crypto samkim-crypto commented Jul 18, 2024

Problem

The syscall ElGamal ciphertext arithmetic functions (the logic in solana_zk_token_sdk::zk_elgamal::ops) have been removed in solana-zk-sdk as they are related specifically to the token program with plans to be moved into the spl repo.

Summary of changes

Added the confidential transfer ciphertext-arithmetic crate that implements the syscall ElGamal ciphertext arithmetic functions.

This is essentially a copy of the logic from solana_zk_token_sdk::zk_elgamal::ops except for the following functions:

  • elgamal_ciphertext_to_ristretto(...): In the zk-token-sdk, (PodPedersenCommitment, PodDecryptHandle)implementedTryFromforPodElGamalCiphertext. However, this was removed in zk-sdkfor simplicity. Theelgamal_ciphertext_to_ristretto(...)was added as a function to directly convert from these two types. The return type is actually(PodRistrettoPoint, PodRistrettoPoint)becausePodRistrettoPoint` is actually the type that is used in the syscall functions.
  • ristretto_to_elgamal_ciphertext(...): This function is the opposite/complement of the function above. Unfortunately, there is one complication with this function. In solana-zk-token-sdk, the PodElGamalCiphertext is defined as PodElGamalCiphertext(pub [u8; 64]). However, in solana-zk-sdk, we have PodElGamalCiphertext(pub(crate) [u8; 64]) and it does not expose a constructor that allows us to create PodElGamalCiphertext from array bytes directly. As a workaround, I ended up converting array bytes into base64 strings and then converting it to PodElGamalCiphertext, since PodElGamalCiphertext does implement FromStr... I think we can use this workaround for now until the next major agave release where we add a proper constructor in solana-zk-sdk.

@samkim-crypto samkim-crypto marked this pull request as ready for review July 18, 2024 11:41
@samkim-crypto samkim-crypto requested a review from joncinque July 18, 2024 11:42
Copy link
Contributor

@joncinque joncinque left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just the one question for future work. We could add a From<[u8; LEN]> implementation for all of them. Doesn't need to be done immediately, of course

Comment on lines +152 to +157
// Unfortunately, the `solana-zk-sdk` does not exporse a constructor interface
// to construct `PodRistrettoPoint` from bytes. As a work-around, encode the
// bytes as base64 string and then convert the string to a
// `PodElGamalCiphertext`.
let ciphertext_string = STANDARD.encode(ciphertext_bytes);
FromStr::from_str(&ciphertext_string).unwrap()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it worth adding the constructor in future work? This seems a bit strange

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we should add the constructor on the zk-sdk side. I'l create an issue on the SPL side to use the new constructor once it lands.

@samkim-crypto samkim-crypto merged commit 3a260d6 into solana-labs:master Jul 19, 2024
31 checks passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants